<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>facebook permissions checking...</title>
<script src="/resources/js/jquery-1.11.0.js"></script>
<script type="text/javascript">
$().ready(function(){
	setTimeout(function(){
		$("#message1").fadeOut();
		$("#message2").fadeIn();
	}, 20000);
});

/* 페이스북 SDK 초기화 */ 
window.fbAsyncInit = function() {
	FB.init({appId: '1470611313169572', status: true, cookie: true,xfbml: true});
	
	FB.getLoginStatus(function(response) {
        if (response.status === 'connected') {
            
            FB.api('/me', function(user) {
                if (user) {
                	
                	for (var key in user) {
                		console.log("Attributes : " + key);
                	}
                	$("#fb_name").val(user.name);
                	$("#fb_id").val(user.id);
                	$("#fb_email").val(user.email);
                	$("#fb_birthday").val(user.birthday);
                	$("#fb_gender").val(user.gender);
                	$("#fb_hometown").val(user.hometown);
                	
                	$("#fm").submit();
                	
                	/* facebook value */
                    /* console.log(user.name);
                    console.log(user.id);
                    console.log(user.email);
                    console.log(user.birthday);
                    console.log(user.gender);
                    console.log(user.locale);
                    console.log(user.timezone);
                    console.log(user.updated_time);
                    console.log(user.username);
                    console.log(user.verified);
                    console.log(user.first_name);
                    console.log(user.last_name);
                    console.log(user.hometown); */
                }
            });
        } else if (response.status === 'not_authorized') {
			
        } else {
        	alert('페이스북 로그인을 해주세요');
            location.href="/home";
        }
    });
	
	
};
	
(function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) return;
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/ko_KR/all.js";
     ref.parentNode.insertBefore(js, ref);
 }(document));
</script>
<link href="/resources/css/font-awesome.css" rel="stylesheet">
<link href="/resources/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
html, body{
	background-color: #E9EAED;
	height: 100%;
}
html {
	display: table;
	width: 100%;
}
body {
	display: table-cell;
	text-align: center;
	vertical-align: middle;
}
.content{
	margin:0 auto;
	background-color: #fff;
}
span{
	color: #555555;
}
</style>
</head>
<body>
<form method="post" action="/fb_getMember" id="fm" name="fm">
	<input type="hidden" id="fb_name" name="fb_name">
	<input type="hidden" id="fb_id" name="fb_id">
	<input type="hidden" id="fb_email" name="fb_email">
	<input type="hidden" id="fb_birthday" name="fb_birthday">
	<input type="hidden" id="fb_gender" name="fb_gender">
	<input type="hidden" id="fb_hometown" name="fb_hometown">
</form>
<div class="col-md-6 col-md-offset-3" >
	<div id="message1">
		<img src="/resources/img/ajax-loader3.gif"><br><br>
		<span class="h3"><i class="fa fa-facebook-square" style="color: #3B5998;"></i></span>&nbsp;<span class="h4">페이스북 로그인 처리중...</span><br>
	</div>
	<div id="message2" style="display: none;">
		<h4><i class="glyphicon glyphicon-remove" style="color: #BF0000;"></i>&nbsp;<span>페이스북 로그인에 실패하였습니다</span></h4> <br>
		<button type="button" class="btn btn-info" onclick="history.back()">돌아가기</button>
	</div>
</div>
</body>
</html>